package com.hexb.smh.controller.management;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import net.sourceforge.pinyin4j.PinyinHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : hexb
 */
@RestController
@RequestMapping("/management/common")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(value = "A99.公共API", description = "Server", tags = {"A99.公共API"})
public class CommonController {


    @ApiOperation("获取文本拼音")
    @GetMapping("/py")
    public String firstLetter(String word) {
        if (!StringUtils.isEmpty(word)) {
            int len = word.length();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < len; i++) {
                char c = word.charAt(i);
                String[] strings = PinyinHelper.toHanyuPinyinStringArray(c);
                if (strings != null && strings.length > 0) {
                    sb.append(strings[0].charAt(0));
                } else {
                    sb.append(c);
                }
            }
            return sb.toString();
        }
        return "";
    }

    @ApiOperation("获取导入模板地址")
    @GetMapping("/templates")
    public Map<String, String> templateUrl() {
        Map<String, String> map = new HashMap<>();
        map.put("salesman", "/template/业务员导入模板.xlsx");
        map.put("product", "/template/项目导入模板.xlsx");
        map.put("commission", "/template/提成率导入模板.xlsx");
        return map;
    }




}
